package com.cy.网络编程.udp.test3;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class Client {
    public static void main(String[] args) throws Exception {
        //从客户顿发送信息
        //1. 快递员
        DatagramSocket ds = new DatagramSocket(9898);

        //客户端发送消息
        byte[] bs = "你好啊".getBytes();
        DatagramPacket dp = new DatagramPacket(bs, bs.length, InetAddress.getByName("localhost"), 7890);
        ds.send(dp);

        //从服务端接收消息
        byte[] bytes = new byte[1024];
        DatagramPacket dp2 = new DatagramPacket(bytes, 1024);
        ds.receive(dp2);
        System.out.println("客户端接受到的消息是："+new String(bytes, 0, dp2.getLength()));
    }
}
